<?php
namespace App\Services\Brand;
use App\Models\Mysql\XuGoodsBrand;
class BrandService
{
    public function get($type = '')
    {
        if($type == 1){
            return XuGoodsBrand::get() -> toArray();
        }else{
            return XuGoodsBrand::select('category_id','category_name','pid','sort')
                -> whereIn('level',[1,2])
                -> orderBy('sort', 'asc')
                -> get()
                -> toArray();
        }
    }

    public function create($code,$pid,$level,$sort){
        return XuGoodsBrand::insert([
            'category_name' => $code,
            'pid' => $pid,
            'level' => $level,
            'is_visible' => 1,
            'sort' => $sort
        ]);
    }

    public function delete($id){
        return XuGoodsBrand::where('category_id','=',$id)->delete();
    }

    public function all($brand_id){
            return XuGoodsBrand::select('category_id','category_name','pid','sort')
            -> where('pid','=',$brand_id)
            -> orderBy('sort','asc')
            -> get()
            -> toArray();
    }
}